﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：DepartMentInfo
// 文件功能描述：部门管理
//
// 
// 创建标识：2012-01-13 周士祎
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class DepartMentInfo
    {
        /// <summary>
        /// 部门编号
        /// </summary>
        public int Dep_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 部门代码
        /// </summary>
        public string Dep_No
        {
            get;
            set;
        }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string DeptName
        {
            get;
            set;
        }
        /// <summary>
        /// 上级部门编号
        /// </summary>
        public int PriorNo
        {
            get;
            set;
        }
        /// <summary>
        /// 部门级别
        /// </summary>
        public int DeptLevel
        {
            get;
            set;
        }

        private DataAccessDepartMent dadm;
        private int rowcount;
        public int _rowcount
        {
            get { return rowcount; }
        }

        public DepartMentInfo()
        {
            dadm = new DataAccessDepartMent();
        }

        public DepartMentInfo(bool isgetcount)
        {
            dadm = new DataAccessDepartMent();
            if (isgetcount)
            {
                rowcount = GetDepartMentCount("");
            }
        }
        /// <summary>
        /// 部门数量合计
        /// </summary>
        /// <returns></returns>
        public int GetDepartMentCount(string Condition)
        {
            return dadm.GetDepartCount(Condition);
        }
        /// <summary>
        /// 获取所有部门信息(分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<DepartMentInfo> GetAllDepartment(string Condition,int pagesize, int startindex)
        {
            IList<DepartMentInfo> dmlist = new List<DepartMentInfo>();
            DepartMentInfo dminfo;
            DataSet ds = dadm.GetAllDepartment(Condition,pagesize, startindex);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new DepartMentInfo()
                {
                    Dep_ID = Convert.ToInt32(item[0]),
                    Dep_No = item[1].ToString(),
                    DeptName = item[2].ToString(),
                    PriorNo = Convert.ToInt32(item[3]),
                    DeptLevel = Convert.ToInt32(item[4])
                };
                dmlist.Add(dminfo);
            }
            return dmlist;
        }
        public IList<DepartMentInfo> GetAllDepartment(string condition)
        {
            IList<DepartMentInfo> dmlist = new List<DepartMentInfo>();
            DepartMentInfo dminfo;
            DataSet ds = dadm.GetAllDepartment(condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {                
                dminfo = new DepartMentInfo()
                {
                    Dep_ID = Convert.ToInt32(item[0]),
                    Dep_No = item[1].ToString(),
                    DeptName = item[2].ToString(),
                    PriorNo = Convert.ToInt32(item[3]),
                    DeptLevel = Convert.ToInt32(item[4])
                };
                dmlist.Add(dminfo);
            }
            return dmlist;
        }
        /// <summary>
        /// 获取部门信息
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public DepartMentInfo GetDepartMentInfo(string condition)
        {            
            DataSet ds = dadm.GetAllDepartment(condition);
            DataRow dr = ds.Tables[0].Rows[0];
            DepartMentInfo dminfo = new DepartMentInfo()
                {
                    Dep_ID = Convert.ToInt32(dr[0]),
                    Dep_No = dr[1].ToString(),
                    DeptName = dr[2].ToString(),
                    PriorNo = Convert.ToInt32(dr[3]),
                    DeptLevel = Convert.ToInt32(dr[4])
                };
            return dminfo;
        }
        /// <summary>
        /// 保存或修改部门信息
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveDepartMent(DepartMentInfo dminfo)
        {
            object[] dpmpara = new object[] { dminfo.Dep_ID,dminfo.Dep_No,dminfo.DeptName,
                                              dminfo.PriorNo,dminfo.DeptLevel };
            return dadm.SaveDepartMent(dpmpara);           
        }
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteDepartMent(string did)
        {
            return dadm.DeleteDepartMent(did);
        }
    }
}
